using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace sla
{
    public partial class MainForm : Form
    {
        SignalsManager signalsManger;
        int panFromPosition;
        int panToPosition;
        bool isPanInProgress;
        public MainForm()
        {
            
            InitializeComponent();
            signalsManger = new SignalsManager(this, 5,this.signalsPanel.Height,this.signalsPanel.Width);
            signalsManger.RefreshAllSignal(int.Parse(this.textBoxTimePerDivision.Text), 0);
            isPanInProgress = false;
        }
       
        public void addToSignalsPannel(PictureBox signalBox)
        {
            signalsPanel.Controls.Add(signalBox);
        
        }


        private void textBoxTimePerDivision_KeyDown(object sender, KeyEventArgs e)
        {
            if (Keys.Enter == e.KeyCode)
            {
                int timePerDivision = (int)float.Parse(this.textBoxTimePerDivision.Text);

                if (0 != timePerDivision)
                {
                    signalsManger.RefreshAllSignal(timePerDivision, (panFromPosition - panToPosition));
                    this.textBoxTimePerDivision.Text = timePerDivision.ToString();
                }
            
            }
        }

        private void signalsPanel_MouseDown(object sender, MouseEventArgs e)
        {
            isPanInProgress = true;
            this.panFromPosition = e.X;
            labelDragFrom.Text = e.X.ToString();

        }

        private void signalsPanel_MouseUp(object sender, MouseEventArgs e)
        {
            isPanInProgress = false;
            this.panToPosition = e.X;
            int timePerDivision = (int)float.Parse(this.textBoxTimePerDivision.Text);
            signalsManger.RefreshAllSignal(timePerDivision, (this.panFromPosition - this.panToPosition));
            labelDragTo.Text = e.X.ToString();

        }

        private void signalsPanel_MouseMove(object sender, MouseEventArgs e)
        {
            int timePerDivision = (int)float.Parse(this.textBoxTimePerDivision.Text);
            labelDelta.Text = ((int)0).ToString();
            if (isPanInProgress)
            {
                this.panToPosition = e.X;
                signalsManger.RefreshAllSignal(timePerDivision, (this.panFromPosition - this.panToPosition));
                labelDragTo.Text = e.X.ToString();
                labelDelta.Text = ((int)(this.panFromPosition - this.panToPosition)).ToString();
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void signalsPanel_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}